package com.pubinfo.passbook.common.model.bo.eip;

import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

@NoArgsConstructor
@Data
public class ReceiveTask {
  private String taskId;
  private String taskname;
  private String taskStatus;
  private String dealerloginname;
  private String todealurl;
  private String mobileUrl;
  private String date;
  private String status;
  
  public ReceiveTask(ReceiveTaskParam param, String status) {
    taskId = param.getTaskId();
    taskname = param.getTaskname();
    taskStatus = "审核员处理";
    dealerloginname = param.getDealerloginname();
    todealurl = param.getTodealurl();
    this.status = status;
    date = DateUtil.format(new Date(), "yyyyMMddhhmmss");
    
  }
  
  public ReceiveTask(String taskId, String status) {
    this.taskId = taskId;
    this.status = status;
  }
  
  public static List<Map<String, String>> toReceiveTask(String taskId, String status) {
    
    List<Map<String, String>> taskList = new ArrayList<>();
    ReceiveTask task = new ReceiveTask(taskId, status);
    Map<String, String> mapItem = JSONObject.parseObject(JSON.toJSONString(task), new TypeReference<Map<String, String>>() {
    });
    taskList.add(mapItem);
    return taskList;
  }
  
  public static List<Map<String, String>> toReceiveTaskList(List<ReceiveTaskParam> paramList, String status) {
    List<Map<String, String>> taskList = new ArrayList<>();
    if (!CollectionUtils.isEmpty(paramList)) {
      for (ReceiveTaskParam param : paramList) {
        ReceiveTask task = new ReceiveTask(param, status);
        Map<String, String> mapItem = JSONObject.parseObject(JSON.toJSONString(task), new TypeReference<Map<String, String>>() {
        });
        taskList.add(mapItem);
      }
    }
    
    return taskList;
  }
}
